package test.udp;

import java.net.InetSocketAddress;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioDatagramConnector;

public class UDPClient {

  private NioDatagramConnector connector;

  private void start() {
    connector=new NioDatagramConnector();
    DefaultIoFilterChainBuilder chain=connector.getFilterChain();
    chain.addLast("logger", new LoggingFilter());
    connector.setHandler(new UDPClientHandler());
    ConnectFuture cf=connector.connect(new InetSocketAddress("localhost", 10000));
    cf.awaitUninterruptibly();
    IoSession session=cf.getSession();
    IoBuffer buf=IoBuffer.allocate(100).setAutoExpand(true);
    buf.putInt(111);
    buf.flip();
    session.write(buf);
  }

  public static void main(String[] args) {
    new UDPClient().start();
  }
}
